home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Exceptions *NOT* being handled properly?!?
- Date: 7 Apr 1996 21:23:33 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4k9bol$fl9@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: ad04-110.compuserve.com
-
- mat@dekard.demon.co.uk (Matt at Home) s'Θcrit :
- > Compiler: gnu g++ v2.7.2 (i386-univel-sysv4.2MP)
- > Environment: UnixWare 2.03 Application Server (16Mb Ram,486DX2-80)
- >
- > Problem: Exceptions do not seem to be handled correctly (according to
- > FAQ 261 of Cline & Lomow)
- >
- > Given the following code
- >
- > class X {};
- > class X2 : public X {}; // X2 is derived from X
- > ....
- > try
- > {
- > throw X2(); // throw the derived class
- > }
- > catch( const X2& e ) // catch the derived class
- > {
- > cerr << "Caught exception: Type X2" << endl;
- > }
- > catch( const X& e ) // catch the base class
- > {
- > cerr << "Caught exception: Type X" << endl;
- > }
- > catch( ... ) // catch anything left over
- > {
- > cerr << "Caught exception: Unknown type" << endl;
- > };
- > ....
- >
- > Running this code correctly gives the output
- >
- > "Caught exception: Type X2"
- >
- > However if we modify to remove the catch-block for X2 giving :-
- >
- > try
- > {
- > throw X2(); // throw the derived class
- > }
- > catch( const X& e ) // catch the base class
- > {
- > cerr << "Caught exception: Type X" << endl;
- > }
- > catch( ... ) // catch anything left over
- > {
- > cerr << "Caught exception: Unknown type" << endl;
- > };
- > ....
- >
- > According to common sense AND to Cline & Lomow FAQ261, I expected :-
- >
- > "Caught exception: Type X"
- >
- > Because X2 is a class derived from X ( i.e. we are catching an
- > exception through the base class, Cline & Lomows xmsg)
- >
- > But instead I get :-
- >
- > "Caught exception: Unknown type"
- >
- > Can someone tell me :-
- >
- > 1. What the correct behaviour is?
- > 2. Is there something wrong with the code I have written (I have
- > similar but *more functional* code which failes the same way in a
- > project)?
- > 3. Is there something wrong with the g++ compiler?
- > 4. If there is, is it likely to be fixed?
- >
- > Regards,
- >
- > "Confused"
- >
- > ----
- > Matt Mower - Information Service Team
- > M19d. The University of North London.
-
- It is clearly a bug in your compiler.
- I tried your example with BC5.0 and it works as
- expected... showing that your X catcher can/must/should
- catch an X2 exception !!
-
-